package com.jfreer.mybatis.expand.xmlmapper.elements;

import com.jfreer.mybatis.expand.IntrospectedTableMyBatis3Freework;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.AbstractXmlElementGenerator;

/**
 * User: landy
 * Date: 14-6-23
 * Time: 上午9:22
 */
public class DeleteAllElementGenerator extends
        AbstractXmlElementGenerator {
    @Override
    public void addElements(XmlElement parentElement) {
        XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$

        answer.addAttribute(new Attribute(
                "id", ((IntrospectedTableMyBatis3Freework) introspectedTable).getDeleteAllStatementId())); //$NON-NLS-1$

        context.getCommentGenerator().addComment(answer);

        StringBuilder sb = new StringBuilder();
        sb.append("delete from "); //$NON-NLS-1$
        sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
        answer.addElement(new TextElement(sb.toString()));


        parentElement.addElement(answer);
    }
}
